using System;
using System.Drawing;
using System.Globalization;
using PickGold.Charting;
using PickGold.Charting.Utilities;

namespace PickGold.Charting.ChartTypes
{
	internal class RangeColumnChart : ColumnChart
	{
		public RangeColumnChart()
		{
			base.useTwoValues = true;
			base.coordinates = COPCoordinates.Y | COPCoordinates.X;
			base.YValueIndex = 1;
		}

		protected override void DrawLabel(ChartArea area, ChartGraphics graph, CommonElements common, RectangleF columnPosition, DataPoint point, Series series, int pointIndex)
		{
			RectangleF ef = RectangleF.Intersect(columnPosition, area.PlotAreaPosition.ToRectangleF());
			if ((ef.Height > 0f) && (ef.Width > 0f))
			{
				PointF empty = PointF.Empty;
				empty.X = ef.X + (ef.Width / 2f);
				empty.Y = ef.Y;
				point.positionRel = new PointF(empty.X, empty.Y);
				int markerSize = point.MarkerSize;
				string markerImage = point.MarkerImage;
				MarkerStyle markerStyle = point.MarkerStyle;
				SizeF size = base.GetMarkerSize(graph, common, area, point, markerSize, markerImage);
				if ((markerStyle != MarkerStyle.None) || (markerImage.Length > 0))
				{
					graph.StartHotRegion(point);
					graph.DrawMarkerRel(empty, (markerStyle == MarkerStyle.None) ? MarkerStyle.Circle : markerStyle, (int)size.Height, (point.MarkerColor == Color.Empty) ? point.Color : point.MarkerColor, (point.MarkerBorderColor == Color.Empty) ? point.BorderColor : point.MarkerBorderColor, this.GetMarkerBorderSize(point), markerImage, point.MarkerImageTransparentColor, (point.series != null) ? point.series.ShadowOffset : 0, (point.series != null) ? point.series.ShadowColor : Color.Empty, new RectangleF(empty.X, empty.Y, size.Width, size.Height));
					graph.EndHotRegion();
					if (common.ProcessModeRegions)
					{
						SizeF relativeSize = graph.GetRelativeSize(size);
						int insertIndex = common.HotRegionsList.FindInsertIndex();
						if (markerStyle == MarkerStyle.Circle)
						{
							float[] numArray = new float[] { empty.X, empty.Y, relativeSize.Width / 2f };
							common.HotRegionsList.AddHotRegion(insertIndex, graph, numArray[0], numArray[1], numArray[2], point, series.Name, pointIndex - 1);
						}
						else
						{
							common.HotRegionsList.AddHotRegion(new RectangleF(empty.X - (relativeSize.Width / 2f), empty.Y - (relativeSize.Height / 2f), relativeSize.Width, relativeSize.Height), point, series.Name, pointIndex - 1);
						}
					}
				}
				using (StringFormat format = new StringFormat())
				{
					format.Alignment = StringAlignment.Center;
					format.LineAlignment = StringAlignment.Center;
					Region clip = graph.Clip;
					graph.Clip = new Region();
					if (point.IsValueShownAsLabel || (point.Label.Length > 0))
					{
						string str2;
						if (point.Label.Length == 0)
						{
							double num3 = this.GetYValue(common, area, series, point, pointIndex, 0);
							str2 = ValueConverter.FormatValue(series.Chart, point, point.Tag, num3, point.LabelFormat, series.YValueType, ChartElementType.DataPoint);
						}
						else
						{
							str2 = point.ReplaceKeywords(point.Label);
						}
						PointF position = PointF.Empty;
						position.X = ef.X + (ef.Width / 2f);
						position.Y = ef.Y + (ef.Height / 2f);
						graph.StartHotRegion(point, true);
						SizeF ef4 = graph.GetRelativeSize(graph.MeasureString(str2, point.Font, new SizeF(1000f, 1000f), StringFormat.GenericTypographic));
						RectangleF backPosition = RectangleF.Empty;
						SizeF ef6 = new SizeF(ef4.Width, ef4.Height);
						ef6.Width += ef6.Width / ((float)str2.Length);
						ef6.Height += ef4.Height / 8f;
						backPosition = PointChart.GetLabelPosition(graph, position, ef6, format, true);
						using (Brush brush = new SolidBrush(point.LabelForeColor))
						{
							graph.DrawPointLabelStringRel(common, str2, point.Font, brush, position, format, point.LabelAngle, backPosition, point.LabelBackColor, point.LabelBorderColor, point.LabelBorderWidth, point.LabelBorderDashStyle, series, point, pointIndex - 1);
						}
						graph.EndHotRegion();
					}
					graph.Clip = clip;
				}
			}
		}

		public override double GetYValue(CommonElements common, ChartArea area, Series series, DataPoint point, int pointIndex, int yValueIndex)
		{
			if (yValueIndex == -1)
			{
				return -(base.GetYValue(common, area, series, point, pointIndex, 1) - base.GetYValue(common, area, series, point, pointIndex, 0));
			}
			return base.GetYValue(common, area, series, point, pointIndex, yValueIndex);
		}

		protected override void ProcessSinglePoint3D(DataPoint3D pointEx, bool selection, ChartGraphics graph, CommonElements common, ChartArea area, RectangleF columnPosition, int pointIndex)
		{
			DataPoint dataPoint = pointEx.dataPoint;
			if (dataPoint.YValues.Length < this.YValuesPerPoint)
			{
				throw new InvalidOperationException(SR.ExceptionChartTypeRequiresYValues(this.Name, this.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
			}
			using (StringFormat format = new StringFormat())
			{
				format.Alignment = StringAlignment.Center;
				format.LineAlignment = StringAlignment.Center;
				Region clip = graph.Clip;
				graph.Clip = new Region();
				if (dataPoint.IsValueShownAsLabel || (dataPoint.Label.Length > 0))
				{
					string str;
					if (dataPoint.Label.Length == 0)
					{
						double num = this.GetYValue(common, area, pointEx.dataPoint.series, dataPoint, pointEx.index - 1, 0);
						str = ValueConverter.FormatValue(pointEx.dataPoint.series.Chart, dataPoint, dataPoint.Tag, num, dataPoint.LabelFormat, pointEx.dataPoint.series.YValueType, ChartElementType.DataPoint);
					}
					else
					{
						str = dataPoint.ReplaceKeywords(dataPoint.Label);
					}
					PointF empty = PointF.Empty;
					empty.X = columnPosition.X + (columnPosition.Width / 2f);
					empty.Y = columnPosition.Y + (columnPosition.Height / 2f);
					Point3D[] points = new Point3D[] { new Point3D(empty.X, empty.Y, pointEx.zPosition + pointEx.depth) };
					area.matrix3D.TransformPoints(points);
					empty.X = points[0].X;
					empty.Y = points[0].Y;
					graph.StartHotRegion(dataPoint, true);
					SizeF relativeSize = graph.GetRelativeSize(graph.MeasureString(str, dataPoint.Font, new SizeF(1000f, 1000f), StringFormat.GenericTypographic));
					RectangleF backPosition = RectangleF.Empty;
					SizeF size = new SizeF(relativeSize.Width, relativeSize.Height);
					size.Width += size.Width / ((float)str.Length);
					size.Height += relativeSize.Height / 8f;
					backPosition = PointChart.GetLabelPosition(graph, empty, size, format, true);
					using (Brush brush = new SolidBrush(dataPoint.LabelForeColor))
					{
						graph.DrawPointLabelStringRel(common, str, dataPoint.Font, brush, empty, format, dataPoint.LabelAngle, backPosition, dataPoint.LabelBackColor, dataPoint.LabelBorderColor, dataPoint.LabelBorderWidth, dataPoint.LabelBorderDashStyle, dataPoint.series, dataPoint, pointIndex);
					}
					graph.EndHotRegion();
				}
				graph.Clip = clip;
			}
		}

		public override bool ExtraYValuesConnectedToYAxis
		{
			get
			{
				return true;
			}
		}

		public override string Name
		{
			get
			{
				return "RangeColumn";
			}
		}

		public override int YValuesPerPoint
		{
			get
			{
				return 2;
			}
		}

		public override bool ZeroCrossing
		{
			get
			{
				return true;
			}
		}
	}
}

